package entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlTransient;
import valueObject.CourseVO;
import valueObject.ProfessorVO;

/**
 *
 * @author David
 */
@Entity
@Table(name = "professor")
@NamedQueries({
    @NamedQuery(name = "ProfessorByUniversity", query = "SELECT p FROM Professor p WHERE p.universityuserUniversity.universityUser = :idU")})
public class Professor implements Serializable, JPAEntity<ProfessorVO> {
    @Id
    @Basic(optional = false)
    @Column(name = "professorUser")
    private String professorUser;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @Column(name = "surname")
    private String surname;
    @Lob
    @Column(name = "description")
    private String description;
    @Column(name = "web")
    private String web;
    @Basic(optional = false)
    @Column(name = "joinDate")
    @Temporal(TemporalType.DATE)
    private Date joinDate;
    @Column(name = "studyLevel")
    private String studyLevel;
    @Column(name = "email")
    private String email;
    @Column(name = "nationality")
    private String nationality;
    @Basic(optional = false)
    @Lob
    @Column(name = "image")
    private byte[] image;
    @ManyToMany(mappedBy = "professorCollection")
    private Collection<Course> courseCollection;
    @JoinColumn(name = "university_userUniversity", referencedColumnName = "universityUser")
    @ManyToOne(optional = false)
    private University universityuserUniversity;

    public Professor() {
    }

    public Professor(String professorUser) {
        this.professorUser = professorUser;
    }

    public Professor(String professorUser, String name, String surname, Date joinDate, byte[] image) {
        this.professorUser = professorUser;
        this.name = name;
        this.surname = surname;
        this.joinDate = joinDate;
        this.image = image;
    }

    public String getProfessorUser() {
        return professorUser;
    }

    public void setProfessorUser(String professorUser) {
        this.professorUser = professorUser;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getWeb() {
        return web;
    }

    public void setWeb(String web) {
        this.web = web;
    }

    public Date getJoinDate() {
        return joinDate;
    }

    public void setJoinDate(Date joinDate) {
        this.joinDate = joinDate;
    }

    public String getStudyLevel() {
        return studyLevel;
    }

    public void setStudyLevel(String studyLevel) {
        this.studyLevel = studyLevel;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getNationality() {
        return nationality;
    }

    public void setNationality(String nationality) {
        this.nationality = nationality;
    }

    public byte[] getImage() {
        return image;
    }

    public void setImage(byte[] image) {
        this.image = image;
    }

    @XmlTransient
    public Collection<Course> getCourseCollection() {
        return courseCollection;
    }

    public void setCourseCollection(Collection<Course> courseCollection) {
        this.courseCollection = courseCollection;
    }

    public University getUniversityuserUniversity() {
        return universityuserUniversity;
    }

    public void setUniversityuserUniversity(University universityuserUniversity) {
        this.universityuserUniversity = universityuserUniversity;
    }

    @Override
    public ProfessorVO toValueObject() {
        ProfessorVO professorVO = new ProfessorVO();
        ArrayList<CourseVO> courseVOs = new ArrayList<CourseVO>();
        if( courseCollection != null){
            for(Course c : courseCollection){
                courseVOs.add(c.toValueObject());
            }
        }
        professorVO.setCourses(courseVOs);
        professorVO.setDescription(description);
        professorVO.setEmail(email);
        professorVO.setImage(image);
        professorVO.setJoinDate(joinDate);
        professorVO.setName(name);
        professorVO.setNationality(nationality);
        professorVO.setUserName(professorUser);
        professorVO.setStudyLevel(studyLevel);
        professorVO.setSurname(surname);
        professorVO.setUniversity(universityuserUniversity.toValueObject());
        professorVO.setWeb(web);
        return professorVO;
    }
    
}